import { Global } from './../../common/global';
import { BusiProvider } from './../../providers/busi/busi';
import { StatusBar } from '@ionic-native/status-bar';
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, AlertController, Platform, App } from 'ionic-angular';
import { NativeProvider } from '../../providers/native/native';

/**
 * Generated class for the MyPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-my',
  templateUrl: 'my.html',
})
export class MyPage {
  xm:string;
  username:string;
  userInfo:any;
  version:any;
  img:any;
  role = Global.role;
  constructor(public navCtrl: NavController, public navParams: NavParams, private busi:BusiProvider,public alertCtrl: AlertController,
    public platform: Platform, public appCtrl: App,private native:NativeProvider) {
  }
  ionViewDidEnter(){
    this.getUserInfo();
  }
  ionViewDidLoad() {
  }
  getUserInfo(){
    this.busi.getUserInfo().subscribe(
      data=>{
        this.userInfo = data.userinfo;
        this.xm = this.userInfo.xm;
        this.username= this.userInfo.username;
        this.img = "assets/imgs/avatar.png";
      },error=>{

      }
    )
  }

  edit(){
    this.navCtrl.push("UsereditPage");
  }

  exitSoftware() {
    this.alertCtrl.create({
      title: '确认退出软件？',
      buttons: [{text: '取消'},
        {
          text: '确定',
          handler: () => {
            this.platform.exitApp();
          }
        }
      ]
    }).present();
  }
  passwordchange(){
    this.navCtrl.push("PasswordchangePage");
  }
  toggleFinger(event){
    //启用
    if(event){
      this.navCtrl.push("FingerPage",{useFinger:true});
    //关闭
    }else{
      this.navCtrl.push("FingerPage",{useFinger:false});
    }
  }
  loginOut(){
    localStorage.removeItem(Global.token);
    localStorage.removeItem(Global.roles);
    this.appCtrl.getRootNav().setRoot("LoginPage");
  }

  imgclick(event){
    event.stopPropagation();
    this.navCtrl.push("UserimageeditPage",{imgurl:this.img});
  }

  newshop(){
    this.navCtrl.push("ShopaddPage");
  }
  myorder(){
    this.navCtrl.push("MyordersPage");
  }
  myproduct(){
    this.navCtrl.push("MyproductPage");
  }
}
